﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DelegateAndEvent
{
    class Program
    {
        static void Main(string[] args)
        {
            #region 委托
            //委托可为空
            Buy buy = null;
            //定义对象
            DelegateBuy d = new DelegateBuy();
            //buy委托对象上有两个功能
            buy = new Buy(d.BuyApple);
            buy += new Buy(d.BuyOrange);
            //调用一次委托，可执行两个加载的功能
            Console.WriteLine(buy("张三"));
            //委托对象作为函数参数
            d.WhoBuy("李四",buy);
            //buy对象去掉某个功能
            buy -= d.BuyApple;
            d.WhoBuy("王五", buy);
            //取消委托
            buy = null;


            #endregion

            #region 事件
            //发布者对象
            EventBuy e = new EventBuy ();
            //订阅者对象
            MrWang wang = new MrWang();
            MrZhang zhang= new MrZhang();
            //订阅者-----注册
            wang.Regsiter(e);
            zhang.Regsiter(e);
            //发布者-----发布信息
            e.Issue();

            #endregion

            #region 事件订阅
            Console.WriteLine("请输入您的取款金额：");
            string amount = Console.ReadLine();
            Console.WriteLine("交易成功，请取出银行卡");
            //事件参数
            UserEventArgs user = new UserEventArgs("xxx@126.com", "13907920000", amount);
            SubscribeSystem sub = new SubscribeSystem(new Bank(), user);



            #endregion



            Console.ReadKey();


        }
    }
}
